home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / samba / patches / samba-1.012 / samba-1
Encoding:
Text File  |  1995-07-11  |  61.2 KB  |  2,106 lines

  1. diff -u -r --new-file last-version/docs/smb.conf.5 samba-1.9.14alpha10/docs/smb.conf.5
  2. --- last-version/docs/smb.conf.5    Thu Jul  6 16:42:42 1995
  3. +++ samba-1.9.14alpha10/docs/smb.conf.5    Tue Jul 11 16:45:14 1995
  4. @@ -332,6 +332,8 @@
  5.  
  6.  dfree command
  7.  
  8. +encrypt passwords
  9. +
  10.  getwd cache
  11.  
  12.  hosts equiv
  13. @@ -366,6 +368,8 @@
  14.  
  15.  packet size
  16.  
  17. +passwd chat
  18. +
  19.  passwd program
  20.  
  21.  password level
  22. @@ -850,6 +854,13 @@
  23.  .B Example:
  24.        dont descend = /proc,/dev
  25.  
  26. +.SS encrypt passwords (G)
  27. +
  28. +This boolean controls whether encrypted passwords will be negotiated
  29. +with the cient. Note that this option has no effect if you haven't
  30. +compiled in the necessary des libraries and encryption code. It
  31. +defaults to no.
  32. +
  33.  .SS exec (S)
  34.  
  35.  This is an alias for preexec
  36. @@ -1483,12 +1494,50 @@
  37.  longer implemented as of version 1.7.00, and is kept only so old
  38.  configuration files do not become invalid.
  39.  
  40. +.SS passwd chat (G)
  41. +This string coontrols the "chat" conversation that takes places
  42. +between smbd and the local password changing program to change the
  43. +users password. The string describes a sequence of response-receive
  44. +pairs that smbd uses to determine what to send to the passwd program
  45. +and what to expect back. If the expected output is not received then
  46. +the password is not changed.
  47. +
  48. +This chat sequence is often quite site specific, deppending on what
  49. +local methods are used for password control (such as NIS+ etc).
  50. +
  51. +The string can contain the macros %o and %n which are substituted for
  52. +the old and new passwords respectively. It can aso contain the
  53. +standard macros \n \r \t and \s to give line-feed, carriage-return,
  54. +tab and space.
  55. +
  56. +The string can also contain a * which matches any sequence of
  57. +characters.
  58. +
  59. +Double quotes can be used to collect strings with spaces in them into
  60. +a single string.
  61. +
  62. +If the send string in any part of the chat sequence is a fullstop "."
  63. +then no string is sent. Similarly, is the expect string is a fullstop
  64. +then no string is expected.
  65. +
  66. +.B Example:
  67. +    passwd chat = "*Enter OLD password*" %o\n "*Enter NEW password*" %n\n \
  68. +                      "*Reenter NEW password*" %n\n "*Password changed*"
  69. +
  70. +.B Default:
  71. +    passwd chat = *old*password* %o\n *new*password* %n\n *new*password* %n\n *changed*
  72. +
  73.  .SS passwd program (G)
  74.  The name of a program that can be used to set user passwords.
  75.  
  76.  This is only necessary if you have enabled remote password changing at
  77.  compile time. Any occurances of %u will be replaced with the user
  78.  name.
  79. +
  80. +Also note that many passwd programs insist in "reasonable" passwords,
  81. +such as a minimum length, or the inclusion of mixed case chars and
  82. +digits. This can pose a problem as some clients (such as Windows for
  83. +Workgroups) uppercase the password before sending it. 
  84.  
  85.  .B Default:
  86.      passwd program = /bin/passwd
  87. diff -u -r --new-file last-version/source/Makefile samba-1.9.14alpha10/source/Makefile
  88. --- last-version/source/Makefile    Sun Jul  9 15:29:01 1995
  89. +++ samba-1.9.14alpha10/source/Makefile    Tue Jul 11 16:28:48 1995
  90. @@ -84,6 +84,11 @@
  91.  # DCE_LIBDIR = -L$(DCE_BASE)/lib
  92.  # DCE_LIBS =
  93.  
  94. +# This is for SMB encrypted (lanman) passwords.
  95. +# DES_BASE=/usr/local/libdes
  96. +# DES_FLAGS= -I$(DES_BASE)
  97. +# DES_LIB= -L$(DES_BASE) -ldes
  98. +# PASSWD_FLAGS=-DSMB_PASSWD -DSMB_PASSWD_FILE=\"$(BASEDIR)/private/smbpasswd\"
  99.  
  100.  #####################################
  101.  # WHICH OPERATING SYSTEM?
  102. @@ -396,10 +401,11 @@
  103.  CFLAGS2 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\" 
  104.  CFLAGS3 = -DLOCKDIR=\"$(LOCKDIR)\" -DSMBRUN=\"$(SMBRUN)\"
  105.  CFLAGS4 = -DWORKGROUP=\"$(WORKGROUP)\" -DGUEST_ACCOUNT=\"$(GUESTACCOUNT)\" 
  106. -CFLAGS  = $(CFLAGS1) $(CFLAGS2) $(CFLAGS3) $(CFLAGS4) $(FLAGSM) $(AFS_FLAGS) $(DCE_FLAGS)
  107. -LIBS = $(LIBS1) $(LIBSM) $(DCE_LIBS)
  108. +CFLAGS5 = $(CFLAGS1) $(CFLAGS2) $(CFLAGS3) $(CFLAGS4) $(FLAGSM) $(AFS_FLAGS) 
  109. +CFLAGS  = $(CFLAGS5) $(DCE_FLAGS) $(DES_FLAGS) $(PASSWD_FLAGS)
  110. +LIBS = $(LIBS1) $(LIBSM) $(DCE_LIBS) $(DES_LIB)
  111.  
  112. -PROGS = smbd smbclient nmbd testparm testprns smbrun smbstatus
  113. +PROGS = smbd smbclient nmbd testparm testprns smbrun smbstatus smbpasswd
  114.  SCRIPTS = smbtar
  115.  
  116.  all : CHECK $(PROGS)
  117. @@ -409,16 +415,19 @@
  118.      @echo "Using CFLAGS = $(CFLAGS)"
  119.      @echo "Using LIBS = $(LIBS)"
  120.  
  121. -INCLUDES1 = version.h local.h includes.h smb.h loadparm.h params.h 
  122. +INCLUDES1 = version.h local.h includes.h smb.h loadparm.h params.h smbpass.h
  123.  INCLUDES2 = pcap.h trans2.h reply.h
  124.  INCLUDES = $(INCLUDES1) $(INCLUDES2)
  125.  
  126.  UTILOBJ = util.o charset.o kanji.o fault.o
  127. -PARAMOBJ = $(UTILOBJ) loadparm.o params.o pcap.o access.o username.o ufc.o 
  128. +PARAMOBJ = $(UTILOBJ) loadparm.o params.o pcap.o access.o username.o ufc.o smbpass.o
  129.  SMBDOBJ1 = $(PARAMOBJ) trans2.o message.o dir.o printing.o locking.o
  130.  SMBDOBJ2 = ipc.o reply.o mangle.o chgpasswd.o password.o
  131.  SMBDOBJ = $(SMBDOBJ1) $(SMBDOBJ2)
  132.  
  133. +.SUFFIXES:
  134. +.SUFFIXES: .c .o .h
  135. +
  136.  .c.o: $*.c $(INCLUDES)
  137.      @echo Compiling $*.c
  138.      @$(CC) $(CFLAGS) -c $*.c
  139. @@ -450,6 +459,10 @@
  140.  testprns: testprns.o $(PARAMOBJ)
  141.      @echo Linking testprns
  142.      @$(CC) $(CFLAGS) -o testprns testprns.o $(PARAMOBJ) $(LIBS)
  143. +
  144. +smbpasswd: smbpasswd.o $(PARAMOBJ)
  145. +    @echo Linking smbpasswd
  146. +    @$(CC) $(CFLAGS) -o smbpasswd smbpasswd.o $(PARAMOBJ) $(LIBS)
  147.  
  148.  install: installbin installman
  149.  
  150. diff -u -r --new-file last-version/source/change-log samba-1.9.14alpha10/source/change-log
  151. --- last-version/source/change-log    Sun Jul  9 16:27:09 1995
  152. +++ samba-1.9.14alpha10/source/change-log    Tue Jul 11 16:47:34 1995
  153. @@ -1513,7 +1513,12 @@
  154.      - client and AFS changes + password.c reorganisation + "more" and
  155.      "pwd" commands in client from Todd j. Derr (tjd@smi.med.pitt.edu)
  156.      - fixed several nmbd bugs
  157. -
  158. +    - released alpha9
  159. +    - fixed another "cd" bug in smbclient
  160. +    - password encryption from Jeremy Allison
  161. +    - added "passwd chat" option and chat interpretation code
  162. +    - added "smb passwd file" option
  163. +    - released alpha10
  164.  
  165.  ==========
  166.  todo:
  167. diff -u -r --new-file last-version/source/chgpasswd.c samba-1.9.14alpha10/source/chgpasswd.c
  168. --- last-version/source/chgpasswd.c    Wed Jul  5 17:28:40 1995
  169. +++ samba-1.9.14alpha10/source/chgpasswd.c    Tue Jul 11 16:32:38 1995
  170. @@ -35,37 +35,10 @@
  171.  #define MINPASSWDLENGTH 5
  172.  #define BUFSIZE 512
  173.  
  174. -static char *P1[] =
  175. -{
  176. -  "*old*password*",
  177. -  ""
  178. -};
  179. -
  180. -static char *P2[] =
  181. -{
  182. -  "*new*password*",
  183. -  ""
  184. -};
  185. -
  186. -static char *P3[] =
  187. -{
  188. -  "*new*password*",
  189. -  ""
  190. -};
  191. -
  192. -static char *P4[] =
  193. -{
  194. -  "\n",
  195. -  "*entry changed*",
  196. -  "*passwd changed*",
  197. -  "*password changed*",
  198. -  ""
  199. -};
  200. -
  201.  static int findpty (char **slave);
  202.  static int talktochild(int master,char *oldpass,char *newpass,char *emess);
  203.  static int dochild(int master,char *slavedev,char *name,char *oldpass,char *newpass);
  204. -static int expect(int master,char **expected,char *buf);
  205. +static int expect(int master,char *expected,char *buf);
  206.  static void writestring (int fd,char *s);
  207.  
  208.  BOOL chgpasswd(char *name,char *oldpass,char *newpass)
  209. @@ -241,61 +214,70 @@
  210.    return(True);
  211.  }
  212.  
  213. +static void pwd_sub(char *buf,char *oldpass,char *newpass)
  214. +{
  215. +  string_sub(buf,"%o",oldpass);
  216. +  string_sub(buf,"%n",newpass);
  217. +  string_sub(buf,"\\n","\n");
  218. +  string_sub(buf,"\\r","\r");
  219. +  string_sub(buf,"\\s"," ");
  220. +  string_sub(buf,"\\t","\t");
  221. +}
  222. +
  223.  static int talktochild (master, oldpass, newpass, emess)
  224.       int master;
  225.       char *oldpass, *newpass, *emess;
  226.  {
  227.    char buf[BUFSIZE];
  228.    char pswd[BUFSIZE+1];
  229. -  
  230. +  int count=0;
  231. +  char *chatsequence = lp_passwd_chat();
  232. +  char *ptr=chatsequence;
  233. +  fstring chatbuf;
  234. +
  235. +  if (!*chatsequence) {
  236. +    DEBUG(0,("No passwd chat sequence - aborting password change\n"));
  237. +  }
  238. +
  239.    *buf = 0;
  240.    *pswd = 0;
  241.    *emess = 0;
  242.    sleep(1);
  243. -  
  244. -  if (!expect(master, P1, buf)) /* Compare what is on the pty with what is stored in P1 */
  245. -    {
  246. -      DEBUG(3,("Response 1 not correct: %s\n",buf));
  247. -      return (False);
  248. -    }
  249.  
  250. -  sprintf(pswd, "%s\n", oldpass);
  251. -  writestring(master, pswd);
  252. +  while (next_token(&ptr,chatbuf,NULL)) {
  253. +    BOOL ok=True;
  254. +    count++;
  255. +    pwd_sub(chatbuf,oldpass,newpass);
  256. +    if (!strequal(chatbuf,"."))
  257. +      ok = expect(master,chatbuf,buf);
  258.  
  259. -  if (!expect(master, P2, buf)) 
  260. -    {
  261. -      DEBUG(3,("Response 2 not correct: %s\n",buf));
  262. -      return(False);
  263. -    }
  264. -
  265. -  sprintf(pswd,"%s\n", newpass);
  266. -  writestring(master, pswd);
  267. +#if DEBUG_PASSWORD
  268. +      DEBUG(100,("chatbuf=[%s] responsebuf=[%s]\n",chatbuf,buf));
  269. +#endif      
  270.  
  271. -  if (!expect(master, P3, buf)) 
  272. -    {
  273. -      DEBUG(3,("Response 3 not correct: %s\n",buf));
  274. +    if (!ok) {
  275. +      DEBUG(3,("response %d incorrect\n",count));
  276.        return(False);
  277.      }
  278.  
  279. -  sprintf(pswd,"%s\n", newpass);
  280. -  writestring(master, pswd);
  281. +    if (!next_token(&ptr,chatbuf,NULL)) break;
  282. +    pwd_sub(chatbuf,oldpass,newpass);
  283. +    if (!strequal(chatbuf,"."))
  284. +      writestring(master,chatbuf);
  285.  
  286. -  if (!expect(master, P4, buf)) 
  287. -    {
  288. -      DEBUG(3,("Response 4 not correct: %s\n",buf));
  289. -      return(False);
  290. -    }
  291. +#if DEBUG_PASSWORD
  292. +    DEBUG(100,("sendbuf=[%s]\n",chatbuf));
  293. +#endif      
  294. +  }
  295.  
  296. +  if (count<1) return(False);
  297. +
  298.    return (True);
  299.  }
  300.  
  301. -static int expect(master, expected, buf)
  302. -     int master;
  303. -     char **expected;
  304. -     char *buf;
  305. +static int expect(int master,char *expected,char *buf)
  306.  {
  307.    int n, m;
  308. -  char **s;
  309.   
  310.    n = 0;
  311.    buf[0] = 0;
  312. @@ -304,21 +286,20 @@
  313.        return False;
  314.      }
  315.  
  316. -    /* allow 2 seconds for some output to appear */
  317. -    m = read_with_timeout(master, buf+n, 1, BUFSIZE-1-n, 2000, True);
  318. -    if (m < 0) return False;
  319. +    /* allow 4 seconds for some output to appear */
  320. +    m = read_with_timeout(master, buf+n, 1, BUFSIZE-1-n, 4000, True);
  321. +    if (m < 0) 
  322. +      return False;
  323.  
  324.      n += m;
  325.      buf[n] = 0;
  326.  
  327. -    for (s = expected; **s != 0; s++) {
  328. -      {
  329. -    string s1,s2;
  330. -    strcpy(s1,buf);
  331. -    strcpy(s2,*s);
  332. -    if (do_match(s1, s2, False))
  333. -      return(True);
  334. -      }
  335. +    {
  336. +      pstring s1,s2;
  337. +      strcpy(s1,buf);
  338. +      strcpy(s2,expected);
  339. +      if (do_match(s1, s2, False))
  340. +    return(True);
  341.      }
  342.    }
  343.  }
  344. diff -u -r --new-file last-version/source/client.c samba-1.9.14alpha10/source/client.c
  345. --- last-version/source/client.c    Sun Jul  9 15:26:37 1995
  346. +++ samba-1.9.14alpha10/source/client.c    Mon Jul 10 09:43:19 1995
  347. @@ -235,8 +235,13 @@
  348.  ****************************************************************************/
  349.  static BOOL chkpath(char *path,BOOL report)
  350.  {
  351. +  fstring path2;
  352.    pstring inbuf,outbuf;
  353.    char *p;
  354. +
  355. +  strcpy(path2,path);
  356. +  trim_string(path2,NULL,"\\");
  357. +  if (!*path2) *path2 = '\\';
  358.  
  359.    bzero(outbuf,smb_size);
  360.    set_message(outbuf,0,4 + strlen(path),True);
  361. diff -u -r --new-file last-version/source/includes.h samba-1.9.14alpha10/source/includes.h
  362. --- last-version/source/includes.h    Thu Jul  6 17:42:16 1995
  363. +++ samba-1.9.14alpha10/source/includes.h    Tue Jul 11 13:35:34 1995
  364. @@ -211,6 +211,7 @@
  365.  #ifdef sun386
  366.  #define NO_STRFTIME
  367.  #define NO_UTIMBUF
  368. +#define mktime timelocal
  369.  typedef unsigned short mode_t;
  370.  #else
  371.  #include <utime.h>
  372. @@ -778,6 +779,9 @@
  373.  #include "version.h"
  374.  #include "smb.h"
  375.  #include "byteorder.h"
  376. +#ifdef SMB_PASSWD
  377. +#include "smbpass.h"
  378. +#endif
  379.  
  380.  #ifdef KANJI
  381.  #ifndef _KANJI_C_
  382. diff -u -r --new-file last-version/source/ipc.c samba-1.9.14alpha10/source/ipc.c
  383. --- last-version/source/ipc.c    Thu Jul  6 22:39:07 1995
  384. +++ samba-1.9.14alpha10/source/ipc.c    Tue Jul 11 13:36:01 1995
  385. @@ -958,7 +958,7 @@
  386.  
  387.    DEBUG(3,("Set password for <%s>\n",user));
  388.  
  389. -  if (!password_ok(user,pass1,NULL) || !chgpasswd(user,pass1,pass2))
  390. +  if (!password_ok(user,pass1,strlen(pass1),NULL) || !chgpasswd(user,pass1,pass2))
  391.      SSVAL(*rparam,0,NERR_badpass);
  392.  
  393.    bzero(pass1,sizeof(fstring));
  394. diff -u -r --new-file last-version/source/loadparm.c samba-1.9.14alpha10/source/loadparm.c
  395. --- last-version/source/loadparm.c    Wed Jul  5 15:19:28 1995
  396. +++ samba-1.9.14alpha10/source/loadparm.c    Tue Jul 11 15:52:32 1995
  397. @@ -120,8 +120,10 @@
  398.     char *szServerString;
  399.     char *szAutoServices;
  400.     char *szPasswdProgram;
  401. +   char *szPasswdChat;
  402.     char *szLogFile;
  403.     char *szConfigFile;
  404. +   char *szSMBPasswdFile;
  405.     char *szPasswordServer;
  406.     char *szSocketOptions;
  407.     char *szValidChars;
  408. @@ -139,6 +141,7 @@
  409.     int printing;
  410.     int maxdisksize;
  411.     int lpqcachetime;
  412. +   BOOL bEncryptPasswords;
  413.     BOOL bStripDot;
  414.     BOOL bNullPasswords;
  415.     BOOL bLoadPrinters;
  416. @@ -327,6 +330,7 @@
  417.    {"printing",         P_INTEGER, P_GLOBAL, &Globals.printing,handle_printing},
  418.    {"max disk size",    P_INTEGER, P_GLOBAL, &Globals.maxdisksize,       NULL},
  419.    {"lpq cache time",   P_INTEGER, P_GLOBAL, &Globals.lpqcachetime,      NULL},
  420. +  {"encrypt passwords",P_BOOL,    P_GLOBAL, &Globals.bEncryptPasswords, NULL},
  421.    {"getwd cache",      P_BOOL,    P_GLOBAL, &use_getwd_cache,           NULL},
  422.    {"read prediction",  P_BOOL,    P_GLOBAL, &Globals.bReadPrediction,   NULL},
  423.    {"read bmpx",        P_BOOL,    P_GLOBAL, &Globals.bReadbmpx,         NULL},
  424. @@ -341,6 +345,7 @@
  425.    {"smbrun",           P_GSTRING, P_GLOBAL, smbrun_path,                NULL},
  426.    {"log file",         P_STRING,  P_GLOBAL, &Globals.szLogFile,         NULL},
  427.    {"config file",      P_STRING,  P_GLOBAL, &Globals.szConfigFile,      NULL},
  428. +  {"smb passwd file",  P_STRING,  P_GLOBAL, &Globals.szSMBPasswdFile,   NULL},
  429.    {"hosts equiv",      P_STRING,  P_GLOBAL, &Globals.szHostsEquiv,      NULL},
  430.    {"preload",          P_STRING,  P_GLOBAL, &Globals.szAutoServices,    NULL},
  431.    {"auto services",    P_STRING,  P_GLOBAL, &Globals.szAutoServices,    NULL},
  432. @@ -357,6 +362,7 @@
  433.    {"message command",  P_STRING,  P_GLOBAL, &Globals.szMsgCommand,      NULL},
  434.    {"dfree command",    P_STRING,  P_GLOBAL, &Globals.szDfree,           NULL},
  435.    {"passwd program",   P_STRING,  P_GLOBAL, &Globals.szPasswdProgram,   NULL},
  436. +  {"passwd chat",      P_STRING,  P_GLOBAL, &Globals.szPasswdChat,      NULL},
  437.    {"valid chars",      P_STRING,  P_GLOBAL, &Globals.szValidChars,      handle_valid_chars},
  438.    {"workgroup",        P_STRING,  P_GLOBAL, &Globals.szWorkGroup,       NULL},
  439.    {"username map",     P_STRING,  P_GLOBAL, &Globals.szUsernameMap,     NULL},
  440. @@ -482,6 +488,10 @@
  441.  
  442.    DEBUG(3,("Initialising global parameters\n"));
  443.  
  444. +#ifdef SMB_PASSWD_FILE
  445. +  string_set(&Globals.szSMBPasswdFile, SMB_PASSWD_FILE);
  446. +#endif
  447. +  string_set(&Globals.szPasswdChat,"*old*password* %o\\n *new*password* %n\\n *new*password* %n\\n *changed*");
  448.    string_set(&Globals.szWorkGroup, WORKGROUP);
  449.    string_set(&Globals.szPasswdProgram, "/bin/passwd");
  450.    string_set(&Globals.szPrintcapname, PRINTCAP_NAME);
  451. @@ -501,6 +511,7 @@
  452.    Globals.max_log_size = 5000;
  453.    Globals.maxprotocol = PROTOCOL_NT1;
  454.    Globals.security = SEC_SHARE;
  455. +  Globals.bEncryptPasswords = False;
  456.    Globals.printing = DEFAULT_PRINTING;
  457.    Globals.bReadRaw = True;
  458.    Globals.bWriteRaw = True;
  459. @@ -594,6 +605,7 @@
  460.  
  461.  FN_GLOBAL_STRING(lp_logfile,&Globals.szLogFile)
  462.  FN_GLOBAL_STRING(lp_configfile,&Globals.szConfigFile)
  463. +FN_GLOBAL_STRING(lp_smb_passwd_file,&Globals.szSMBPasswdFile)
  464.  FN_GLOBAL_STRING(lp_serverstring,&Globals.szServerString)
  465.  FN_GLOBAL_STRING(lp_printcapname,&Globals.szPrintcapname)
  466.  FN_GLOBAL_STRING(lp_lockdir,&Globals.szLockDir)
  467. @@ -604,6 +616,7 @@
  468.  FN_GLOBAL_STRING(lp_hosts_equiv,&Globals.szHostsEquiv)
  469.  FN_GLOBAL_STRING(lp_auto_services,&Globals.szAutoServices)
  470.  FN_GLOBAL_STRING(lp_passwd_program,&Globals.szPasswdProgram)
  471. +FN_GLOBAL_STRING(lp_passwd_chat,&Globals.szPasswdChat)
  472.  FN_GLOBAL_STRING(lp_passwordserver,&Globals.szPasswordServer)
  473.  FN_GLOBAL_STRING(lp_workgroup,&Globals.szWorkGroup)
  474.  FN_GLOBAL_STRING(lp_username_map,&Globals.szUsernameMap)
  475. @@ -617,6 +630,8 @@
  476.  FN_GLOBAL_BOOL(lp_writeraw,&Globals.bWriteRaw)
  477.  FN_GLOBAL_BOOL(lp_null_passwords,&Globals.bNullPasswords)
  478.  FN_GLOBAL_BOOL(lp_strip_dot,&Globals.bStripDot)
  479. +FN_GLOBAL_BOOL(lp_encrypted_passwords,&Globals.bEncryptPasswords)
  480. +
  481.  
  482.  FN_GLOBAL_INTEGER(lp_max_log_size,&Globals.max_log_size)
  483.  FN_GLOBAL_INTEGER(lp_mangledstack,&Globals.mangled_stack)
  484. diff -u -r --new-file last-version/source/loadparm.h samba-1.9.14alpha10/source/loadparm.h
  485. --- last-version/source/loadparm.h    Wed Jul  5 15:14:47 1995
  486. +++ samba-1.9.14alpha10/source/loadparm.h    Tue Jul 11 15:49:06 1995
  487. @@ -38,11 +38,13 @@
  488.  extern BOOL lp_manglednames(int iService);
  489.  extern char *lp_passwordserver(void);
  490.  extern char *lp_passwd_program(void);
  491. +extern char *lp_passwd_chat(void);
  492.  extern char *lp_guestaccount(int iService);
  493.  extern char *lp_printcapname(void);
  494.  extern char *lp_lockdir(void);
  495.  extern char *lp_logfile(void);
  496.  extern char *lp_configfile(void);
  497. +extern char *lp_smb_passwd_file(void);
  498.  extern char *lp_rootdir(void);
  499.  extern char *lp_defaultservice(void);
  500.  extern char *lp_serverstring(void);
  501. @@ -66,6 +68,7 @@
  502.  extern BOOL lp_writeraw(void);
  503.  extern BOOL lp_null_passwords(void);
  504.  extern BOOL lp_strip_dot(void);
  505. +extern BOOL lp_encrypted_passwords(void);
  506.  extern int  lp_numservices(void);
  507.  extern int  lp_keepalive(void);
  508.  extern int  lp_passwordlevel(void);
  509. diff -u -r --new-file last-version/source/locking.c samba-1.9.14alpha10/source/locking.c
  510. --- last-version/source/locking.c    Wed Jul  5 01:30:06 1995
  511. +++ samba-1.9.14alpha10/source/locking.c    Tue Jul 11 15:02:01 1995
  512. @@ -27,131 +27,6 @@
  513.  
  514.  pstring share_del_pending="";
  515.  
  516. -/****************************************************************************
  517. -routine to do file locking
  518. -****************************************************************************/
  519. -static BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type)
  520. -{
  521. -#if HAVE_FCNTL_LOCK
  522. -  struct flock lock;
  523. -  int ret;
  524. -
  525. -#if 1
  526. -  uint32 mask = 0xC0000000;
  527. -
  528. -  /* make sure the count is reasonable, we might kill the lockd otherwise */
  529. -  count &= ~mask;
  530. -
  531. -  /* the offset is often strange - remove 2 of its bits if either of
  532. -     the top two bits are set. Shift the top ones by two bits. This
  533. -     still allows OLE2 apps to operate, but should stop lockd from
  534. -     dieing */
  535. -  if ((offset & mask) != 0)
  536. -    offset = (offset & ~mask) | ((offset & mask) >> 2);
  537. -#else
  538. -  unsigned long mask = ((unsigned)1<<31);
  539. -
  540. -  /* interpret negative counts as large numbers */
  541. -  if (count < 0)
  542. -    count &= ~mask;
  543. -
  544. -  /* no negative offsets */
  545. -  offset &= ~mask;
  546. -
  547. -  /* count + offset must be in range */
  548. -  while ((offset < 0 || (offset + count < 0)) && mask)
  549. -    {
  550. -      offset &= ~mask;
  551. -      mask = mask >> 1;
  552. -    }
  553. -#endif
  554. -
  555. -
  556. -  DEBUG(5,("fcntl_lock %d %d %d %d %d\n",fd,op,(int)offset,(int)count,type));
  557. -
  558. -  lock.l_type = type;
  559. -  lock.l_whence = SEEK_SET;
  560. -  lock.l_start = (int)offset;
  561. -  lock.l_len = (int)count;
  562. -  lock.l_pid = 0;
  563. -
  564. -  errno = 0;
  565. -
  566. -  ret = fcntl(fd,op,&lock);
  567. -
  568. -  if (errno != 0)
  569. -    DEBUG(3,("fcntl lock gave errno %d (%s)\n",errno,strerror(errno)));
  570. -
  571. -  /* a lock query */
  572. -  if (op == F_GETLK)
  573. -    {
  574. -      if ((ret != -1) &&
  575. -      (lock.l_type != F_UNLCK) && 
  576. -      (lock.l_pid != 0) && 
  577. -      (lock.l_pid != getpid()))
  578. -    {
  579. -      DEBUG(3,("fd %d is locked by pid %d\n",fd,lock.l_pid));
  580. -      return(True);
  581. -    }
  582. -
  583. -      /* it must be not locked or locked by me */
  584. -      return(False);
  585. -    }
  586. -
  587. -  /* a lock set or unset */
  588. -  if (ret == -1)
  589. -    {
  590. -      DEBUG(3,("lock failed at offset %d count %d op %d type %d (%s)\n",
  591. -           offset,count,op,type,strerror(errno)));
  592. -
  593. -      /* perhaps it doesn't support this sort of locking?? */
  594. -      if (errno == EINVAL)
  595. -    {
  596. -      DEBUG(3,("locking not supported? returning True\n"));
  597. -      return(True);
  598. -    }
  599. -
  600. -      return(False);
  601. -    }
  602. -
  603. -  /* everything went OK */
  604. -  DEBUG(5,("Lock call successful\n"));
  605. -
  606. -  return(True);
  607. -#else
  608. -  return(False);
  609. -#endif
  610. -}
  611. -
  612. -/*******************************************************************
  613. -lock a file - returning a open file descriptor or -1 on failure
  614. -The timeout is in seconds. 0 means no timeout
  615. -********************************************************************/
  616. -int file_lock(char *name,int timeout)
  617. -{  
  618. -  int fd = open(name,O_RDWR|O_CREAT,0666);
  619. -  time_t t=0;
  620. -  if (fd < 0) return(-1);
  621. -
  622. -  if (timeout) t = time(NULL);
  623. -  while (!timeout || (time(NULL)-t < timeout)) {
  624. -    if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)) return(fd);    
  625. -    msleep(LOCK_RETRY_TIMEOUT);
  626. -  }
  627. -  
  628. -  return(-1);
  629. -}
  630. -
  631. -/*******************************************************************
  632. -unlock a file locked by file_lock
  633. -********************************************************************/
  634. -void file_unlock(int fd)
  635. -{
  636. -  if (fd<0) return;
  637. -  fcntl_lock(fd,F_SETLK,0,1,F_UNLCK);
  638. -  close(fd);
  639. -}
  640. -
  641.  
  642.  /****************************************************************************
  643.    utility function called to see if a file region is locked
  644. diff -u -r --new-file last-version/source/mksmbpasswd.sh samba-1.9.14alpha10/source/mksmbpasswd.sh
  645. --- last-version/source/mksmbpasswd.sh    Thu Jan  1 10:00:00 1970
  646. +++ samba-1.9.14alpha10/source/mksmbpasswd.sh    Tue Jul 11 13:41:45 1995
  647. @@ -0,0 +1,6 @@
  648. +#!/bin/sh
  649. +awk 'BEGIN {FS=":"
  650. +    printf("#\n# SMB password file.\n#\n")
  651. +    }
  652. +{ printf( "%s:%s:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:%s:%s:%s\n", $1, $3, $5, $6, $7) }
  653. +'
  654. diff -u -r --new-file last-version/source/password.c samba-1.9.14alpha10/source/password.c
  655. --- last-version/source/password.c    Sun Jul  9 15:07:48 1995
  656. +++ samba-1.9.14alpha10/source/password.c    Tue Jul 11 16:45:47 1995
  657. @@ -28,7 +28,42 @@
  658.  /* users from session setup */
  659.  pstring session_users="";
  660.  
  661. +#ifdef SMB_PASSWD
  662. +/* Data to do lanman1/2 password challenge. */
  663. +static unsigned char saved_challenge[8];
  664. +static BOOL challenge_sent=False;
  665.  
  666. +/*******************************************************************
  667. +Get the next challenge value - no repeats.
  668. +********************************************************************/
  669. +void generate_next_challenge(char *challenge)
  670. +{
  671. +  extern void E1(char *,char *,char *);
  672. +  static int counter = 0;
  673. +  struct timeval tval;
  674. +  int v1,v2;
  675. +  GetTimeOfDay(&tval);
  676. +  v1 = (counter++) + getpid() + tval.tv_sec;
  677. +  v2 = (counter++) * getpid() + tval.tv_usec;
  678. +  SIVAL(challenge,0,v1);
  679. +  SIVAL(challenge,4,v2);
  680. +  E1(challenge,"SAMBA",saved_challenge);
  681. +  memcpy(challenge,saved_challenge,8);
  682. +  challenge_sent = True;
  683. +}
  684. +
  685. +/*******************************************************************
  686. +get the last challenge sent
  687. +********************************************************************/
  688. +BOOL last_challenge(char *challenge)
  689. +{
  690. +  if (!challenge_sent) return(False);
  691. +  memcpy(challenge,saved_challenge,8);
  692. +  challenge_sent = False;
  693. +  return(True);
  694. +}
  695. +#endif
  696. +
  697.  /* this holds info on user ids that are already validated for this VC */
  698.  user_struct *validated_users = NULL;
  699.  int num_validated_users = 0;
  700. @@ -418,23 +453,83 @@
  701.    return(strcmp((char *)crypt(password,this_salt),this_crypted) == 0);
  702.  }
  703.  
  704. +#ifdef SMB_PASSWD
  705. +/****************************************************************************
  706. +core of smb password checking routine.
  707. +****************************************************************************/
  708. +BOOL smb_password_check(char *password, unsigned char *part_passwd, unsigned char *c8)
  709. +{
  710. +  /* Finish the encryption of part_passwd. */
  711. +  unsigned char p21[21];
  712. +  unsigned char p24[24];
  713. +
  714. +  if(part_passwd == NULL)
  715. +    DEBUG(10,("No password set - allowing access\n"));
  716. +  /* No password set - always true ! */
  717. +  if(part_passwd == NULL)
  718. +    return 1;
  719. +
  720. +  memset(p21,'\0',21);
  721. +  memcpy(p21,part_passwd,16);
  722. +  E_P24(p21, c8, p24);
  723. +#if DEBUG_PASSWORD
  724. +  {
  725. +    int i;
  726. +    DEBUG(100,("Part password (P16) was |"));
  727. +    for(i = 0; i < 16; i++)
  728. +      DEBUG(100,("%X ", (unsigned char)part_passwd[i]));
  729. +    DEBUG(100,("|\n"));
  730. +    DEBUG(100,("Password from client was |"));
  731. +    for(i = 0; i < 24; i++)
  732. +      DEBUG(100,("%X ", (unsigned char)password[i]));
  733. +    DEBUG(100,("|\n"));
  734. +    DEBUG(100,("Given challenge was |"));
  735. +    for(i = 0; i < 8; i++)
  736. +      DEBUG(100,("%X ", (unsigned char)c8[i]));
  737. +    DEBUG(100,("|\n"));
  738. +    DEBUG(100,("Value from encryption was |"));
  739. +    for(i = 0; i < 24; i++)
  740. +      DEBUG(100,("%X ", (unsigned char)p24[i]));
  741. +    DEBUG(100,("|\n"));
  742. +  }
  743. +#endif
  744. +  return (memcmp(p24, password, 24) == 0);
  745. +}
  746. +#endif
  747. +
  748.  /****************************************************************************
  749.  check if a username/password is OK
  750.  ****************************************************************************/
  751. -BOOL password_ok(char *user,char *password, struct passwd *pwd)
  752. +BOOL password_ok(char *user,char *password, int pwlen, struct passwd *pwd)
  753.  {
  754.    pstring pass2;
  755.    int level = lp_passwordlevel();
  756.    struct passwd *pass;
  757. +#ifdef SMB_PASSWD
  758. +  char challenge[8];
  759. +  struct smb_passwd *smb_pass;
  760. +  BOOL challenge_done = last_challenge(challenge);
  761. +#endif
  762.  
  763.  #if DEBUG_PASSWORD
  764. -  DEBUG(100,("checking user=[%s] pass=[%s]\n",user,password));
  765. +#ifdef SMB_PASSWD
  766. +  int i;
  767. +  if((pwlen == 24) && challenge_done)
  768. +    {
  769. +      DEBUG(100,("checking user=[%s] pass=[",user));
  770. +      for( i = 0; i < 24; i++)
  771. +    DEBUG(100,("%0x ", (unsigned char)password[i]));
  772. +      DEBUG(100,("]\n"));
  773. +    }
  774. +  else
  775. +#endif
  776. +    DEBUG(100,("checking user=[%s] pass=[%s]\n",user,password));
  777.  #endif
  778.  
  779.    if (!password)
  780.      return(False);
  781.  
  782. -  if (!*password && !lp_null_passwords())
  783. +  if (!pwlen && !lp_null_passwords())
  784.      return(False);
  785.  
  786.    if (pwd && !user) 
  787. @@ -445,7 +540,40 @@
  788.    else 
  789.      pass = Get_Pwnam(user,True);
  790.  
  791. -  DEBUG(4,("Checking password for user %s (l=%d)\n",user,strlen(password)));
  792. +#ifdef SMB_PASSWD
  793. +  if((pwlen == 24) && challenge_done)
  794. +    {
  795. +      DEBUG(4,("Checking password for user %s (l=24)\n",user));
  796. +
  797. +      if (!pass) 
  798. +    {
  799. +      DEBUG(3,("Couldn't find user %s\n",user));
  800. +      return(False);
  801. +    }
  802. +
  803. +      smb_pass = get_smbpwnam(user);
  804. +      if(!smb_pass)
  805. +    {
  806. +      DEBUG(3,("Couldn't find user %s in smb_passwd file.\n", user));
  807. +      return(False);
  808. +    }
  809. +
  810. +      /* Ensure the uid's match */
  811. +      if(smb_pass->smb_userid != pass->pw_uid)
  812. +    {
  813. +      DEBUG(3,("Error : UNIX and SMB uids in password files do not match !\n"));
  814. +      return(False);
  815. +    }
  816. +
  817. +      if(smb_password_check(password, smb_pass->smb_passwd, challenge))
  818. +    {
  819. +      update_protected_database(user,True);
  820. +      return(True);
  821. +    }
  822. +    }
  823. +#endif 
  824. +
  825. +  DEBUG(4,("Checking password for user %s (l=%d)\n",user,pwlen));
  826.  
  827.    if (!pass) 
  828.      {
  829. @@ -516,7 +644,6 @@
  830.  #endif    
  831.    }
  832.  
  833. -
  834.    /* try it as it came to us */
  835.    if (password_check(password))
  836.      {
  837. @@ -605,7 +732,7 @@
  838.  /****************************************************************************
  839.  validate a group username entry. Return the username or NULL
  840.  ****************************************************************************/
  841. -static char *validate_group(char *group,char *password,int snum)
  842. +static char *validate_group(char *group,char *password,int pwlen,int snum)
  843.  {
  844.  #if HAVE_GETGRNAM 
  845.    struct group *gptr = (struct group *)getgrnam(group);
  846. @@ -618,7 +745,7 @@
  847.        static fstring name;
  848.        strcpy(name,*member);
  849.        if (user_ok(name,snum) &&
  850. -          password_ok(name,password,NULL))
  851. +          password_ok(name,password,pwlen,NULL))
  852.          return(&name[0]);
  853.        member++;
  854.      }
  855. @@ -631,7 +758,7 @@
  856.        while (pwd = getpwent ()) {
  857.            if (*(pwd->pw_passwd) && pwd->pw_gid == gptr->gr_gid) {
  858.            /* This Entry have PASSWORD and same GID then check pwd */
  859. -          if (password_ok(0, password, pwd)) {
  860. +          if (password_ok(0, password, pwlen, pwd)) {
  861.                strcpy(tm, pwd->pw_name);
  862.                endpwent ();
  863.                return tm;
  864. @@ -651,7 +778,7 @@
  865.  /****************************************************************************
  866.  check for authority to login to a service with a given username/password
  867.  ****************************************************************************/
  868. -BOOL authorise_login(int snum,char *user,char *password,BOOL *guest,int vuid)
  869. +BOOL authorise_login(int snum,char *user,char *password, int pwlen, BOOL *guest,int vuid)
  870.  {
  871.    BOOL ok = False;
  872.    
  873. @@ -678,14 +805,14 @@
  874.  
  875.        /* check the given username and password */
  876.        if (!ok && (*user) && user_ok(user,snum)) {
  877. -    ok = password_ok(user,password, NULL);
  878. +    ok = password_ok(user,password, pwlen, NULL);
  879.      if (ok) DEBUG(3,("ACCEPTED: given username password ok\n"));
  880.        }
  881.  
  882.        /* check for a previously registered guest username */
  883.        if (!ok && (vuid >= 0) && validated_users[vuid].guest) {      
  884.      if (user_ok(validated_users[vuid].name,snum) &&
  885. -        password_ok(validated_users[vuid].name, password, NULL)) {
  886. +        password_ok(validated_users[vuid].name, password, pwlen, NULL)) {
  887.        strcpy(user, validated_users[vuid].name);
  888.        validated_users[vuid].guest = False;
  889.        DEBUG(3,("ACCEPTED: given password with registered user %s\n", user));
  890. @@ -709,7 +836,7 @@
  891.            strcpy(user2,auser);
  892.            if (!user_ok(user2,snum)) continue;
  893.            
  894. -          if (password_ok(user2,password, NULL)) {
  895. +          if (password_ok(user2,password, pwlen, NULL)) {
  896.          ok = True;
  897.          strcpy(user,user2);
  898.          DEBUG(3,("ACCEPTED: session list username and given password ok\n"));
  899. @@ -748,7 +875,7 @@
  900.        {
  901.          if (*auser == '@')
  902.            {
  903. -        auser = validate_group(auser+1,password,snum);
  904. +        auser = validate_group(auser+1,password,pwlen,snum);
  905.          if (auser)
  906.            {
  907.              ok = True;
  908. @@ -760,7 +887,7 @@
  909.            {
  910.          fstring user2;
  911.          strcpy(user2,auser);
  912. -        if (user_ok(user2,snum) && password_ok(user2,password,NULL))
  913. +        if (user_ok(user2,snum) && password_ok(user2,password,pwlen,NULL))
  914.            {
  915.              ok = True;
  916.              strcpy(user,user2);
  917. diff -u -r --new-file last-version/source/reply.c samba-1.9.14alpha10/source/reply.c
  918. --- last-version/source/reply.c    Fri Jul  7 15:09:51 1995
  919. +++ samba-1.9.14alpha10/source/reply.c    Tue Jul 11 14:41:21 1995
  920. @@ -120,14 +120,15 @@
  921.    int outsize = 0;
  922.    int uid = SVAL(inbuf,smb_uid);
  923.    int vuid;
  924. +  int pwlen;
  925.  
  926.    *service = *user = *password = *dev = 0;
  927.  
  928.    vuid = valid_uid(uid);
  929.    
  930. -  parse_connect(inbuf,service,user,password,dev);
  931. +  parse_connect(inbuf,service,user,password,&pwlen,dev);
  932.  
  933. -  connection_num = make_connection(service,user,password,dev,vuid);
  934. +  connection_num = make_connection(service,user,password,pwlen,dev,vuid);
  935.    
  936.    if (connection_num < 0)
  937.      switch (connection_num)
  938. @@ -168,6 +169,7 @@
  939.    int vuid;
  940.    int smb_com2 = SVAL(inbuf,smb_vwv0);
  941.    int smb_off2 = SVAL(inbuf,smb_vwv1);
  942. +  int passlen = SVAL(inbuf,smb_vwv3);
  943.  
  944.    *service = *user = *password = *devicename = 0;
  945.  
  946. @@ -178,7 +180,6 @@
  947.    vuid = valid_uid(uid);
  948.    
  949.    {
  950. -    int passlen = SVAL(inbuf,smb_vwv3);
  951.      char *path;
  952.      char *p;
  953.      memcpy(password,smb_buf(inbuf),passlen);
  954. @@ -201,7 +202,7 @@
  955.      DEBUG(4,("Got device type %s\n",devicename));
  956.    }
  957.  
  958. -  connection_num = make_connection(service,user,password,devicename,vuid);
  959. +  connection_num = make_connection(service,user,password,passlen,devicename,vuid);
  960.    
  961.    if (connection_num < 0)
  962.      switch (connection_num)
  963. @@ -303,17 +304,25 @@
  964.    } else {
  965.      uint16 passlen1 = SVAL(inbuf,smb_vwv7);
  966.      uint16 passlen2 = SVAL(inbuf,smb_vwv8);
  967. +    BOOL doencrypt = SMBENCRYPT();
  968.      char *p = smb_buf(inbuf);
  969.      if (passlen1 > 256) passlen1 = 0;
  970.      if (passlen2 > 256) passlen2 = 0; /* I don't know why NT gives weird 
  971.                      lengths sometimes */
  972. -    /* for Win95 */
  973. -    if (passlen1 > passlen2) {
  974. +    if(doencrypt) {
  975. +      /* Use the lanman2 password for now until the NT md4 password
  976. +     is worked out. */
  977.        smb_apasslen = passlen1;
  978. -      StrnCpy(smb_apasswd,p,smb_apasslen);
  979. +      memcpy(smb_apasswd,p,smb_apasslen);
  980.      } else {
  981. -      smb_apasslen = passlen2;
  982. -      StrnCpy(smb_apasswd,p + passlen1,smb_apasslen);
  983. +      /* for Win95 */
  984. +      if (passlen1 > passlen2) {
  985. +    smb_apasslen = passlen1;
  986. +    StrnCpy(smb_apasswd,p,smb_apasslen);
  987. +      } else {
  988. +    smb_apasslen = passlen2;
  989. +    StrnCpy(smb_apasswd,p + passlen1,smb_apasslen);
  990. +      }
  991.      }
  992.      p += passlen1 + passlen2;
  993.      strcpy(user,p); p = skip_string(p,1);
  994. @@ -344,7 +353,7 @@
  995.      guest = True;
  996.    
  997.        /* now check if it's a valid username/password */
  998. -      if (!guest && !password_ok(user,smb_apasswd, NULL))
  999. +      if (!guest && !password_ok(user,smb_apasswd,smb_apasslen,NULL))
  1000.      {
  1001.  #if !GUEST_SESSSETUP
  1002.        if (lp_security() >= SEC_USER)
  1003. diff -u -r --new-file last-version/source/server.c samba-1.9.14alpha10/source/server.c
  1004. --- last-version/source/server.c    Fri Jul  7 15:03:30 1995
  1005. +++ samba-1.9.14alpha10/source/server.c    Tue Jul 11 14:58:25 1995
  1006. @@ -98,6 +98,9 @@
  1007.  
  1008.  static int find_free_connection(int hash);
  1009.  
  1010. +#ifdef SMB_PASSWD
  1011. +extern void generate_next_challenge(char *challenge);
  1012. +#endif
  1013.  
  1014.  /* for readability... */
  1015.  #define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0)
  1016. @@ -1834,7 +1837,7 @@
  1017.  /****************************************************************************
  1018.    make a connection to a service
  1019.  ****************************************************************************/
  1020. -int make_connection(char *service,char *user,char *password,char *dev,int vuid)
  1021. +int make_connection(char *service,char *user,char *password, int pwlen, char *dev,int vuid)
  1022.  {
  1023.    int cnum;
  1024.    int snum;
  1025. @@ -1860,12 +1863,12 @@
  1026.    if (strequal(service,HOMES_NAME))
  1027.      {
  1028.        if (*user && Get_Pwnam(user,True))
  1029. -    return(make_connection(user,user,password,dev,vuid));
  1030. +    return(make_connection(user,user,password,pwlen,dev,vuid));
  1031.  
  1032.        if (validated_username(vuid))
  1033.      {
  1034.        strcpy(user,validated_username(vuid));
  1035. -      return(make_connection(user,user,password,dev,vuid));
  1036. +      return(make_connection(user,user,password,pwlen,dev,vuid));
  1037.      }
  1038.      }
  1039.  
  1040. @@ -1896,7 +1899,7 @@
  1041.    add_session_user(service);
  1042.  
  1043.    /* shall we let them in? */
  1044. -  if (!authorise_login(snum,user,password,&guest,vuid))
  1045. +  if (!authorise_login(snum,user,password,pwlen,&guest,vuid))
  1046.      {
  1047.        DEBUG(2,("%s invalid username/password for %s\n",timestring(),service));
  1048.        return(-1);
  1049. @@ -2234,9 +2237,7 @@
  1050.    SSVAL(outbuf,smb_vwv5,raw); /* tell redirector we support
  1051.                   readbraw and writebraw (possibly) */
  1052.    CVAL(outbuf,smb_flg) = 0x81; /* Reply, SMBlockread, SMBwritelock supported */
  1053. -#ifdef TESTING
  1054.    SSVAL(outbuf,smb_vwv1,0x1); /* user level security, don't encrypt */    
  1055. -#endif
  1056.  
  1057.    Protocol = PROTOCOL_COREPLUS;
  1058.  
  1059. @@ -2250,9 +2251,21 @@
  1060.  int reply_lanman1(char *outbuf)
  1061.  {
  1062.    int raw = (lp_readraw()?1:0) | (lp_writeraw()?2:0);
  1063. -  int outsize = set_message(outbuf,13,0,True);
  1064. +  int outsize;
  1065. +  int secword=0;
  1066. +  BOOL doencrypt = SMBENCRYPT();
  1067. +
  1068. +  if (lp_security()>=SEC_USER) secword |= 1;
  1069. +  if (doencrypt) secword |= 2;
  1070. +
  1071. +  outsize = set_message(outbuf,13,doencrypt?8:0,True);
  1072. +  SSVAL(outbuf,smb_vwv1,secword); 
  1073. +#ifdef SMB_PASSWD
  1074. +  /* Create a token value and add it to the outgoing packet. */
  1075. +  if (doencrypt) 
  1076. +    generate_next_challenge(smb_buf(outbuf));
  1077. +#endif
  1078.    CVAL(outbuf,smb_flg) = 0x81; /* Reply, SMBlockread, SMBwritelock supported */
  1079. -  SSVAL(outbuf,smb_vwv1,(lp_security()>=SEC_USER)?1:0); /* user level security? don't encrypt */    
  1080.    SSVAL(outbuf,smb_vwv2,maxxmit);
  1081.    SSVAL(outbuf,smb_vwv3,lp_maxmux()); /* maxmux */
  1082.    SSVAL(outbuf,smb_vwv4,1);
  1083. @@ -2275,10 +2288,21 @@
  1084.  int reply_lanman2(char *outbuf)
  1085.  {
  1086.    int raw = (lp_readraw()?1:0) | (lp_writeraw()?2:0);
  1087. -
  1088. -  set_message(outbuf,13,0,True);
  1089. +  int outsize;
  1090. +  int secword=0;
  1091. +  BOOL doencrypt = SMBENCRYPT();
  1092. +
  1093. +  if (lp_security()>=SEC_USER) secword |= 1;
  1094. +  if (doencrypt) secword |= 2;
  1095. +
  1096. +  outsize = set_message(outbuf,13,doencrypt?8:0,True);
  1097. +  SSVAL(outbuf,smb_vwv1,secword); 
  1098. +#ifdef SMB_PASSWD
  1099. +  /* Create a token value and add it to the outgoing packet. */
  1100. +  if (doencrypt) 
  1101. +    generate_next_challenge(smb_buf(outbuf));
  1102. +#endif
  1103.  
  1104. -  SSVAL(outbuf,smb_vwv1,(lp_security()>=SEC_USER)?1:0);
  1105.    SIVAL(outbuf,smb_vwv6,getpid());
  1106.  
  1107.    Protocol = PROTOCOL_LANMAN2;
  1108. @@ -2295,18 +2319,32 @@
  1109.    SSVAL(outbuf,smb_vwv10, TimeDiff(0)/60);
  1110.    put_dos_date(outbuf,smb_vwv8,time(NULL));
  1111.  
  1112. -  return (smb_len(outbuf)+4);
  1113. +  return (outsize);
  1114.  }
  1115.  
  1116.  /****************************************************************************
  1117. -reply for the lanman 2.0 protocol
  1118. +reply for the nt protocol
  1119.  ****************************************************************************/
  1120.  int reply_nt1(char *outbuf)
  1121.  {
  1122.    int capabilities=0x300; /* has dual names + lock_and_read */
  1123. +  int secword=0;
  1124. +  BOOL doencrypt = SMBENCRYPT();
  1125. +
  1126. +  if (lp_security()>=SEC_USER) secword |= 1;
  1127. +  if (doencrypt) secword |= 2;
  1128. +
  1129. +  set_message(outbuf,17,doencrypt?8:0,True);
  1130. +  CVAL(outbuf,smb_vwv1) = secword;
  1131. +#ifdef SMB_PASSWD
  1132. +  /* Create a token value and add it to the outgoing packet. */
  1133. +  if (doencrypt) {
  1134. +    generate_next_challenge(smb_buf(outbuf));
  1135. +    /* Tell the nt machine how long the challenge is. */
  1136. +    SSVALS(outbuf,smb_vwv16+1,8);
  1137. +  }
  1138. +#endif
  1139.  
  1140. -  set_message(outbuf,17,0,True);
  1141. -  CVAL(outbuf,smb_vwv1) = (lp_security()>=SEC_USER)?1:0;
  1142.    SIVAL(outbuf,smb_vwv7+1,getpid()); /* session key */
  1143.  
  1144.    Protocol = PROTOCOL_NT1;
  1145. @@ -2417,7 +2455,7 @@
  1146.  /****************************************************************************
  1147.    parse a connect packet
  1148.  ****************************************************************************/
  1149. -void parse_connect(char *buf,char *service,char *user,char *password,char *dev)
  1150. +void parse_connect(char *buf,char *service,char *user,char *password,int *pwlen,char *dev)
  1151.  {
  1152.    char *p = smb_buf(buf) + 1;
  1153.    char *p2;
  1154. @@ -2433,6 +2471,7 @@
  1155.    p += strlen(p) + 2;
  1156.    
  1157.    strcpy(password,p);
  1158. +  *pwlen = strlen(password);
  1159.  
  1160.    p += strlen(p) + 2;
  1161.  
  1162. @@ -3809,7 +3848,6 @@
  1163.      exit(1);
  1164.        }
  1165.  
  1166. -  
  1167.    reopen_logs();
  1168.  
  1169.    DEBUG(2,("%s smbd version %s started\n",timestring(),VERSION));
  1170. diff -u -r --new-file last-version/source/smb.h samba-1.9.14alpha10/source/smb.h
  1171. --- last-version/source/smb.h    Fri Jul  7 14:59:25 1995
  1172. +++ samba-1.9.14alpha10/source/smb.h    Tue Jul 11 15:03:11 1995
  1173. @@ -355,6 +355,11 @@
  1174.  #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
  1175.  #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
  1176.  #define CREATE_MODE(cnum)  (lp_create_mode(SNUM(cnum)) | 0700)
  1177. +#ifdef SMB_PASSWD
  1178. +#define SMBENCRYPT()       (lp_encrypted_passwords())
  1179. +#else
  1180. +#define SMBENCRYPT() (False)
  1181. +#endif
  1182.  
  1183.  /* the basic packet size, assuming no words or bytes */
  1184.  #define smb_size 39
  1185. @@ -548,6 +553,7 @@
  1186.  };
  1187.  
  1188.  /* and a few prototypes */
  1189. +BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type);
  1190.  void BlockSignals(BOOL block);
  1191.  void msleep(int t);
  1192.  int file_lock(char *name,int timeout);
  1193. @@ -625,8 +631,8 @@
  1194.  int seek_file(int fnum,int pos);
  1195.  BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
  1196.  int get_printqueue(int snum,int cnum,print_queue_struct **queue,print_status_struct *status);
  1197. -void parse_connect(char *buf,char *service,char *user,char *password,char *dev);
  1198. -int make_connection(char *service,char *user,char *password,char *dev,int vuid);
  1199. +void parse_connect(char *buf,char *service,char *user,char *password,int *pwlen,char *dev);
  1200. +int make_connection(char *service,char *user,char *password, int pwlen, char *dev,int vuid);
  1201.  char *dptr_path(int key);
  1202.  char *dptr_wcard(int key);
  1203.  BOOL dptr_set_wcard(int key, char *wcard);
  1204. @@ -646,10 +652,10 @@
  1205.  int reply_trans2(char *inbuf,char *outbuf,int length,int bufsize);
  1206.  int reply_trans(char *inbuf,char *outbuf);
  1207.  char *ufc_crypt(char *key,char *salt);
  1208. -BOOL authorise_login(int snum,char *user,char *password,BOOL *guest,int vuid);
  1209. +BOOL authorise_login(int snum,char *user,char *password, int pwlen, BOOL *guest,int vuid);
  1210.  void add_session_user(char *user);
  1211.  int valid_uid(int uid);
  1212. -BOOL password_ok(char *user,char *password, struct passwd *pwd);
  1213. +BOOL password_ok(char *user,char *password, int pwlen, struct passwd *pwd);
  1214.  void register_uid(int uid,char *name,BOOL guest);
  1215.  BOOL fromhost(int sock,struct from_host *f);
  1216.  BOOL strhasupper(char *s);
  1217. diff -u -r --new-file last-version/source/smbpass.c samba-1.9.14alpha10/source/smbpass.c
  1218. --- last-version/source/smbpass.c    Thu Jan  1 10:00:00 1970
  1219. +++ samba-1.9.14alpha10/source/smbpass.c    Tue Jul 11 15:15:19 1995
  1220. @@ -0,0 +1,316 @@
  1221. +#ifdef SMB_PASSWD
  1222. +/* 
  1223. +   Unix SMB/Netbios implementation.
  1224. +   Version 1.9.
  1225. +   SMB parameters and setup
  1226. +   Copyright (C) Andrew Tridgell 1992-1995
  1227. +   Modified by Jeremy Allison 1995.
  1228. +   
  1229. +   This program is free software; you can redistribute it and/or modify
  1230. +   it under the terms of the GNU General Public License as published by
  1231. +   the Free Software Foundation; either version 2 of the License, or
  1232. +   (at your option) any later version.
  1233. +   
  1234. +   This program is distributed in the hope that it will be useful,
  1235. +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1236. +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1237. +   GNU General Public License for more details.
  1238. +   
  1239. +   You should have received a copy of the GNU General Public License
  1240. +   along with this program; if not, write to the Free Software
  1241. +   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1242. +*/
  1243. +
  1244. +#include "includes.h"
  1245. +#include "loadparm.h"
  1246. +#include "des.h"
  1247. +
  1248. +extern int DEBUGLEVEL;
  1249. +
  1250. +#define uchar unsigned char
  1251. +
  1252. +void str_to_key(uchar *str,uchar *key)
  1253. +{
  1254. +  int i;
  1255. +
  1256. +  key[0] = str[0]>>1;
  1257. +  key[1] = ((str[0]&0x01)<<6) | (str[1]>>2);
  1258. +  key[2] = ((str[1]&0x03)<<5) | (str[2]>>3);
  1259. +  key[3] = ((str[2]&0x07)<<4) | (str[3]>>4);
  1260. +  key[4] = ((str[3]&0x0F)<<3) | (str[4]>>5);
  1261. +  key[5] = ((str[4]&0x1F)<<2) | (str[5]>>6);
  1262. +  key[6] = ((str[5]&0x3F)<<1) | (str[6]>>7);
  1263. +  key[7] = str[6]&0x7F;
  1264. +  for (i=0;i<8;i++) {
  1265. +    key[i] = (key[i]<<1);
  1266. +  }
  1267. +  des_set_odd_parity(key);
  1268. +}
  1269. +
  1270. +void D1(uchar *k, uchar *d, uchar *out)
  1271. +{
  1272. +  des_key_schedule ks;
  1273. +  des_cblock deskey;
  1274. +
  1275. +  str_to_key(k,(uchar *)deskey);
  1276. +  des_set_key(deskey,ks);
  1277. +  des_ecb_encrypt(d, out, ks, DES_DECRYPT);
  1278. +}
  1279. +
  1280. +void E1(uchar *k, uchar *d, uchar *out)
  1281. +{
  1282. +  des_key_schedule ks;
  1283. +  des_cblock deskey;
  1284. +
  1285. +  str_to_key(k,(uchar *)deskey);
  1286. +  des_set_key(deskey,ks);
  1287. +  des_ecb_encrypt(d, out, ks, DES_ENCRYPT);
  1288. +}
  1289. +void E_P16(uchar *p14,uchar *p16)
  1290. +{
  1291. +  uchar sp7[7];
  1292. +  uchar sp8[] = {0xAA,0xD3,0xB4,0x35,0xB5,0x14,0x4,0xEE};
  1293. +  uchar x[8];
  1294. +
  1295. +  memset(sp7,'\0',7);
  1296. +
  1297. +  D1(sp7, sp8, x);
  1298. +  E1(p14, x, p16);
  1299. +  E1(p14+7, x, p16+8);
  1300. +}
  1301. +
  1302. +void E_P24(uchar *p21, uchar *c8, uchar *p24)
  1303. +{
  1304. +  E1(p21, c8, p24);
  1305. +  E1(p21+7, c8, p24+8);
  1306. +  E1(p21+14, c8, p24+16);
  1307. +}
  1308. +
  1309. +
  1310. +/*
  1311. +   This implements the X/Open SMB password encryption
  1312. +   It takes a password, a 8 byte "crypt key" and puts 24 bytes of 
  1313. +   encrypted password into p24
  1314. +*/
  1315. +void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
  1316. +{
  1317. +  uchar p14[14], p21[21];
  1318. +
  1319. +  memset(p21,'\0',21);
  1320. +  memset(p14,'\0',14);
  1321. +  strncpy((char *)p14,(char *)passwd,14);
  1322. +
  1323. +  E_P16(p14, p21);
  1324. +  E_P24(p21, c8, p24);
  1325. +}
  1326. +
  1327. +/* Try and get a lock on the first byte of the
  1328. +   file. If this fails wait 5 seconds then try again.
  1329. +   If this fails then return an error. This ensures a 
  1330. +   consistant view is always seen as all processes updating
  1331. +   this file should finish within 5 seconds.
  1332. +*/
  1333. +
  1334. +static int gotalarm;
  1335. +
  1336. +void gotalarm_sig()
  1337. +{
  1338. +  gotalarm = 1;
  1339. +}
  1340. +
  1341. +/* Static buffers we will return. */
  1342. +static struct smb_passwd pw_buf;
  1343. +static pstring user_name;
  1344. +static unsigned char smbpwd[16];
  1345. +
  1346. +/*
  1347. + * Routine to search the smbpasswd file for an
  1348. + * entry matching the username.
  1349. + */
  1350. +struct smb_passwd *get_smbpwnam(const char *name)
  1351. +{
  1352. +  char linebuf[256];
  1353. +  unsigned char c;
  1354. +  unsigned char *p;
  1355. +  unsigned char *newp;
  1356. +  long uidval;
  1357. +  long linebuf_len;
  1358. +  unsigned char lonybble, hinybble;
  1359. +  int i;
  1360. +  FILE *fp;
  1361. +  int lockfd;
  1362. +  char *pfile = lp_smb_passwd_file();
  1363. +
  1364. +  if (!*pfile) {
  1365. +    DEBUG(0,("No SMB password file set\n"));
  1366. +    return(NULL);
  1367. +  }
  1368. +
  1369. +  DEBUG(10,("get_smbpwnam: opening file %s\n", pfile));
  1370. +  
  1371. +  fp = fopen(pfile,"r");
  1372. +  
  1373. +  if(fp == NULL) 
  1374. +    {
  1375. +      DEBUG(0,("get_smbpwnam: unable to open file %s\n", pfile));
  1376. +      return NULL;
  1377. +    }
  1378. +  
  1379. +  if((lockfd = file_lock(pfile,5))<0) {
  1380. +    DEBUG(0,("get_smbpwnam: unable to lock file %s\n", pfile));
  1381. +    fclose(fp);
  1382. +    return NULL;
  1383. +  }
  1384. +
  1385. +  /* make sure it is only rw by the owner */
  1386. +  fchmod(fileno(fp),0600);
  1387. +  
  1388. +  /* We have a read lock on the file. */
  1389. +  /* Scan the file, a line at a time and
  1390. +     check if the name matches. */
  1391. +  while(!feof(fp)) 
  1392. +    {
  1393. +      linebuf[0] = '\0';
  1394. +
  1395. +      fgets(linebuf, 256, fp);
  1396. +      if(ferror(fp))
  1397. +    {
  1398. +      fclose(fp);
  1399. +      file_unlock(lockfd);
  1400. +      return NULL;
  1401. +    }
  1402. +
  1403. +      /* Check if the string is terminated with a newline -
  1404. +     if not then we must keep reading and discard until
  1405. +     we get one.
  1406. +     */
  1407. +      linebuf_len = strlen(linebuf);
  1408. +      if(linebuf[linebuf_len-1] != '\n')
  1409. +    {
  1410. +      c = '\0';
  1411. +      while(!ferror(fp) && !feof(fp))
  1412. +        {
  1413. +          c = fgetc(fp);
  1414. +          if(c == '\n')
  1415. +        break;
  1416. +        }
  1417. +    }
  1418. +      else
  1419. +    linebuf[linebuf_len-1] = '\0';
  1420. +
  1421. +#ifdef DEBUG_PASSWORD
  1422. +      DEBUG(100, ("get_smbpwnam: got line |%s|\n", linebuf));
  1423. +#endif
  1424. +      if((linebuf[0] == 0) && feof(fp))
  1425. +    {
  1426. +      DEBUG(4,("get_smbpwnam: end of file reached\n"));
  1427. +      break;
  1428. +    }
  1429. +      /* The line we have should be of the form :-
  1430. +     
  1431. +     username:uid:[32hex bytes]:....other flags presently ignored....
  1432. +     
  1433. +     */
  1434. +
  1435. +      if(linebuf[0] == '#' || linebuf[0] == '\0')
  1436. +    {
  1437. +      DEBUG(4,("get_smbpwnam: skipping comment or blank line\n"));
  1438. +      continue;
  1439. +    }
  1440. +      p = (unsigned char *)strchr(linebuf, ':');
  1441. +      if( p == NULL)
  1442. +    {
  1443. +      DEBUG(0,("get_smbpwnam: malformed password entry (no :)\n"));
  1444. +      continue;
  1445. +    }
  1446. +      /* As 256 is shorter than a pstring we don't
  1447. +     need to check length here - if this ever changes.... */
  1448. +      strncpy( user_name, linebuf, (char *)p - linebuf);
  1449. +      user_name[(char *)p - linebuf] = '\0';
  1450. +      if(strcasecmp(user_name, name))
  1451. +    continue;
  1452. +
  1453. +      /* User name matches - get uid and password */
  1454. +      p++;            /* Go past ':' */
  1455. +      if(!isdigit(*p))
  1456. +    {
  1457. +      DEBUG(0,("get_smbpwnam: malformed password entry (uid not number)\n"));
  1458. +      fclose(fp);
  1459. +      file_unlock(lockfd);
  1460. +      return NULL;
  1461. +    }
  1462. +
  1463. +      uidval = strtol((char *)p, (char **)&newp, 10);
  1464. +      if(*newp != ':')
  1465. +    {
  1466. +      DEBUG(0,("get_smbpwnam: malformed password entry (no : after uid)\n"));
  1467. +      fclose(fp);
  1468. +      file_unlock(lockfd);
  1469. +      return NULL;
  1470. +    }
  1471. +
  1472. +      /* Now get the password value - this should be 32 hex digits which
  1473. +     are the ascii representations of a 16 byte string. Get two at
  1474. +     a time and put them into the password.
  1475. +     */
  1476. +      p = newp + 1;
  1477. +      if(*p == '*' || *p == 'X')
  1478. +    {
  1479. +      /* Password deliberately invalid - end here. */
  1480. +      DEBUG(10,("get_smbpwnam: entry invalidated for user %s\n",user_name));
  1481. +      fclose(fp);
  1482. +      file_unlock(lockfd);
  1483. +      return NULL;
  1484. +    }
  1485. +      if(linebuf_len < ((char *)p - linebuf + 33))
  1486. +    {
  1487. +      DEBUG(0,("get_smbpwnam: malformed password entry (passwd too short)\n"));
  1488. +      fclose(fp);
  1489. +      file_unlock(lockfd);
  1490. +      return(False);
  1491. +    }
  1492. +
  1493. +      if(p[32] != ':')
  1494. +    {
  1495. +      DEBUG(0,("get_smbpwnam: malformed password entry (no terminating :)\n"));
  1496. +      fclose(fp);
  1497. +      file_unlock(lockfd);
  1498. +      return NULL;
  1499. +    }
  1500. +
  1501. +      if(strncasecmp((char *)p,"NO PASSWORD",11) == 0) {
  1502. +    pw_buf.smb_passwd = NULL;
  1503. +      } else {
  1504. +    for(i = 0; i < 32; i += 2)
  1505. +      {
  1506. +        hinybble = toupper(p[i]);
  1507. +        if(isdigit(hinybble))
  1508. +          hinybble -= '0';
  1509. +        else
  1510. +          hinybble = (hinybble - 'A') + 10;
  1511. +        lonybble = toupper(p[i+1]);
  1512. +        if(isdigit(lonybble))
  1513. +          lonybble -= '0';
  1514. +        else
  1515. +          lonybble = (lonybble - 'A') + 10;
  1516. +        smbpwd[i/2] = (hinybble << 4) | lonybble;
  1517. +      }
  1518. +    pw_buf.smb_passwd = smbpwd;
  1519. +      }
  1520. +      pw_buf.smb_name = user_name;
  1521. +      pw_buf.smb_userid = uidval;
  1522. +      fclose(fp);
  1523. +      file_unlock(lockfd);
  1524. +      DEBUG(5, ("get_smbpwname: returning passwd entry for user %s, uid %d\n",
  1525. +        user_name, uidval));
  1526. +      return &pw_buf;
  1527. +    }
  1528. +  
  1529. +  fclose(fp);
  1530. +  file_unlock(lockfd);
  1531. +  return NULL;
  1532. +}
  1533. +#else
  1534. +char smbpass_dummy[1]; /* To avoid compiler complaints */
  1535. +#endif
  1536. diff -u -r --new-file last-version/source/smbpass.h samba-1.9.14alpha10/source/smbpass.h
  1537. --- last-version/source/smbpass.h    Thu Jan  1 10:00:00 1970
  1538. +++ samba-1.9.14alpha10/source/smbpass.h    Tue Jul 11 13:41:27 1995
  1539. @@ -0,0 +1,47 @@
  1540. +#ifndef _SMBPASS_H_
  1541. +#define _SMBPASS_H_
  1542. +/* 
  1543. +   Unix SMB/Netbios implementation.
  1544. +   Version 1.9.
  1545. +   SMB parameters and setup
  1546. +   Copyright (C) Jeremy Allison 1995
  1547. +   
  1548. +   This program is free software; you can redistribute it and/or modify
  1549. +   it under the terms of the GNU General Public License as published by
  1550. +   the Free Software Foundation; either version 2 of the License, or
  1551. +   (at your option) any later version.
  1552. +   
  1553. +   This program is distributed in the hope that it will be useful,
  1554. +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1555. +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1556. +   GNU General Public License for more details.
  1557. +   
  1558. +   You should have received a copy of the GNU General Public License
  1559. +   along with this program; if not, write to the Free Software
  1560. +   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1561. +*/
  1562. +
  1563. +struct smb_passwd {
  1564. +    int smb_userid;
  1565. +    char *smb_name;
  1566. +    unsigned char *smb_passwd; /* Null if no password */
  1567. +    /* Other fields / flags may be added later */
  1568. +};
  1569. +
  1570. +/* Return a smb_passwd struct given a user name, 0 if fails. */
  1571. +struct smb_passwd *get_smbpwnam(const char *user);
  1572. +
  1573. +/* Lock the password file */
  1574. +int do_pw_lock(int, int);
  1575. +
  1576. +#ifndef uchar
  1577. +#define uchar unsigned char
  1578. +#endif
  1579. +
  1580. +/* SMB Encryption functions. */
  1581. +void str_to_key(unsigned char *str,unsigned char *key);
  1582. +void E_P16(uchar *p14,uchar *p16);
  1583. +void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24);
  1584. +void SMBencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24);
  1585. +
  1586. +#endif
  1587. diff -u -r --new-file last-version/source/smbpasswd.c samba-1.9.14alpha10/source/smbpasswd.c
  1588. --- last-version/source/smbpasswd.c    Thu Jan  1 10:00:00 1970
  1589. +++ samba-1.9.14alpha10/source/smbpasswd.c    Tue Jul 11 15:30:14 1995
  1590. @@ -0,0 +1,368 @@
  1591. +#ifdef SMB_PASSWD
  1592. +
  1593. +/* 
  1594. +   Unix SMB/Netbios implementation.
  1595. +   Version 1.9.
  1596. +   smbpasswd module.
  1597. +   Copyright (C) Jeremy Allison 1995.
  1598. +
  1599. +   This program is free software; you can redistribute it and/or modify
  1600. +   it under the terms of the GNU General Public License as published by
  1601. +   the Free Software Foundation; either version 2 of the License, or
  1602. +   (at your option) any later version.
  1603. +   
  1604. +   This program is distributed in the hope that it will be useful,
  1605. +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1606. +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1607. +   GNU General Public License for more details.
  1608. +   
  1609. +   You should have received a copy of the GNU General Public License
  1610. +   along with this program; if not, write to the Free Software
  1611. +   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1612. +*/
  1613. +
  1614. +#include "includes.h"
  1615. +#include "des.h"
  1616. +
  1617. +/* Static buffers we will return. */
  1618. +static struct smb_passwd pw_buf;
  1619. +static pstring user_name;
  1620. +static unsigned char smbpwd[16];
  1621. +
  1622. +struct smb_passwd *_my_get_smbpwnam(FILE *fp, const char *name, BOOL *valid_old_pwd, long *pwd_seekpos)
  1623. +{
  1624. +    char linebuf[256];
  1625. +    unsigned char c;
  1626. +    unsigned char *p;
  1627. +    unsigned char *newp;
  1628. +    long uidval;
  1629. +    long linebuf_len;
  1630. +    unsigned char lonybble, hinybble;
  1631. +    int i;
  1632. +
  1633. +    /* Scan the file, a line at a time and
  1634. +       check if the name matches. */
  1635. +    while(!feof(fp)) 
  1636. +      {
  1637. +        linebuf[0] = '\0';
  1638. +        *pwd_seekpos = ftell(fp);
  1639. +
  1640. +        fgets(linebuf, 256, fp);
  1641. +        if(ferror(fp))
  1642. +            return NULL;
  1643. +
  1644. +        /* Check if the string is terminated with a newline -
  1645. +            if not then we must keep reading and discard until
  1646. +            we get one.
  1647. +        */
  1648. +        linebuf_len = strlen(linebuf);
  1649. +        if(linebuf[linebuf_len-1] != '\n')
  1650. +          {
  1651. +            c = '\0';
  1652. +            while(!ferror(fp) && !feof(fp))
  1653. +              {
  1654. +                c = fgetc(fp);
  1655. +                if(c == '\n')
  1656. +                    break;
  1657. +              }
  1658. +          }
  1659. +        else
  1660. +            linebuf[linebuf_len-1] = '\0';
  1661. +
  1662. +        if((linebuf[0] == 0) && feof(fp))
  1663. +            break;
  1664. +        /* The line we have should be of the form :-
  1665. +
  1666. +        username:uid:[32hex bytes]:....other flags presently ignored....
  1667. +
  1668. +        */
  1669. +
  1670. +        if(linebuf[0] == '#' || linebuf[0] == '\0')
  1671. +            continue;
  1672. +        p = (unsigned char *)strchr(linebuf, ':');
  1673. +        if( p == NULL)
  1674. +            continue;
  1675. +        /* As 256 is shorter than a pstring we don't
  1676. +           need to check length here - if this ever changes.... */
  1677. +        strncpy( user_name, linebuf, (char *)p - linebuf);
  1678. +        user_name[(char *)p - linebuf] = '\0';
  1679. +        if(strcasecmp(user_name, name))
  1680. +            continue;
  1681. +
  1682. +        /* User name matches - get uid and password */
  1683. +        p++; /* Go past ':' */
  1684. +        if(!isdigit(*p))
  1685. +            return(False);
  1686. +
  1687. +        uidval = strtol((char *)p, (char **)&newp, 10);
  1688. +        if(*newp != ':')
  1689. +            return(False);
  1690. +
  1691. +        /* Now get the password value - this should be 32 hex digits which
  1692. +           are the ascii representations of a 16 byte string. Get two at
  1693. +           a time and put them into the password.
  1694. +        */
  1695. +        p = newp + 1;
  1696. +        *pwd_seekpos += ((char *)p - linebuf); /* Save exact position of
  1697. +                         passwd in file - this is used
  1698. +                         by smbpasswd.c 
  1699. +                      */
  1700. +        if(*p == '*' || *p == 'X')
  1701. +          {
  1702. +            /* Password deliberately invalid - end here. */
  1703. +            *valid_old_pwd = False;
  1704. +            pw_buf.smb_name = user_name;
  1705. +            pw_buf.smb_userid = uidval;
  1706. +            return(&pw_buf);
  1707. +          }
  1708. +        if(linebuf_len < ((char *)p - linebuf + 33))
  1709. +            return(False);
  1710. +
  1711. +        if(p[32] != ':')
  1712. +            return(False);
  1713. +
  1714. +        if(strncasecmp(p,"NO PASSWORD",11) == 0) {
  1715. +            pw_buf.smb_passwd = NULL; /* No password */
  1716. +        } else {
  1717. +            for(i = 0; i < 32; i += 2)
  1718. +              {
  1719. +                hinybble = toupper(p[i]);
  1720. +                if(isdigit(hinybble))
  1721. +                    hinybble -= '0';
  1722. +                else
  1723. +                    hinybble = (hinybble - 'A') + 10;
  1724. +                lonybble = toupper(p[i+1]);
  1725. +                if(isdigit(lonybble))
  1726. +                    lonybble -= '0';
  1727. +                else
  1728. +                    lonybble = (lonybble - 'A') + 10;
  1729. +                smbpwd[i/2] = (hinybble << 4) | lonybble;
  1730. +              }
  1731. +            pw_buf.smb_passwd = smbpwd;
  1732. +        }
  1733. +
  1734. +        pw_buf.smb_name = user_name;
  1735. +        pw_buf.smb_userid = uidval;
  1736. +        *valid_old_pwd = True;
  1737. +        return &pw_buf;
  1738. +    }
  1739. +    return NULL;
  1740. +}
  1741. +
  1742. +/*
  1743. + * Print command usage on stderr and die.
  1744. + */
  1745. +
  1746. +void usage(const char *name)
  1747. +{
  1748. +    fprintf(stderr, "Usage is : %s [username]\n", name);
  1749. +    exit(1);
  1750. +}
  1751. +
  1752. +int main(int argc, char **argv)
  1753. +{
  1754. +    int real_uid;
  1755. +    struct passwd *pwd;
  1756. +    fstring old_passwd;
  1757. +    uchar old_p16[16];
  1758. +    fstring new_passwd;
  1759. +    uchar new_p16[16];
  1760. +    char *p;
  1761. +    struct smb_passwd *smb_pwent;
  1762. +    FILE *fp;
  1763. +    BOOL valid_old_pwd = False;
  1764. +    long seekpos;
  1765. +    int pwfd;
  1766. +    char ascii_p16[33];
  1767. +    char c;
  1768. +    int ret, i, err;
  1769. +    int lockfd=-1;
  1770. +    char *pfile = SMB_PASSWD_FILE;
  1771. +
  1772. +    charset_initialise();
  1773. +
  1774. +#ifndef DEBUG_PASSWORD
  1775. +    /* Check the effective uid */
  1776. +    if(geteuid() != 0) {
  1777. +        fprintf(stderr, "%s: Must be setuid root.\n", argv[0]);
  1778. +        exit(1);
  1779. +    }
  1780. +#endif
  1781. +
  1782. +    /* Get the real uid */
  1783. +    real_uid = getuid();
  1784. +
  1785. +    /* Deal with usage problems */
  1786. +    if( real_uid == 0) {
  1787. +        /* As root we can change anothers password. */
  1788. +        if(argc != 1 && argc != 2)
  1789. +            usage(argv[0]);
  1790. +    } else if(argc != 1)
  1791. +        usage(argv[0]);
  1792. +        
  1793. +
  1794. +    if(real_uid == 0 && argc == 2) {
  1795. +        /* If we are root we can change anothers password. */
  1796. +        strncpy( user_name, argv[1], sizeof(user_name)-1);
  1797. +        user_name[sizeof(user_name)-1] = '\0';
  1798. +        pwd = getpwnam( user_name );
  1799. +    } else {
  1800. +        pwd = getpwuid( real_uid );
  1801. +    }
  1802. +
  1803. +    if(pwd == 0) {
  1804. +        fprintf(stderr, "%s: Unable to get UNIX password entry for user.\n", argv[0]);
  1805. +        exit(1);
  1806. +    }
  1807. +
  1808. +    /* If we are root we don't ask for the old password. */
  1809. +    old_passwd[0] = '\0';
  1810. +    if(real_uid != 0) {
  1811. +        p = getpass("Old SMB password:");
  1812. +        strncpy(old_passwd, p, 14);
  1813. +        old_passwd[14] = '\0';
  1814. +        strupper(old_passwd);
  1815. +    }
  1816. +
  1817. +    new_passwd[0] = '\0';
  1818. +    p = getpass("New SMB password:");
  1819. +    strncpy(new_passwd, p, 14);
  1820. +    new_passwd[14] = '\0';
  1821. +    p = getpass("Retype new SMB password:");
  1822. +    if(strncmp(p, new_passwd, 14)) {
  1823. +        fprintf(stderr, "%s: Mismatch - password unchanged.\n", argv[0]);
  1824. +        exit(1);
  1825. +    }
  1826. +    strupper(new_passwd);
  1827. +
  1828. +    if(new_passwd[0] == '\0') {
  1829. +        printf("Password not set\n");
  1830. +        exit(0);
  1831. +    }
  1832. +
  1833. +    /* Calculate the SMB hash functions of
  1834. +       both old an new passwords. */
  1835. +
  1836. +    memset(old_p16,'\0',16);
  1837. +    E_P16((uchar *)old_passwd,old_p16);
  1838. +
  1839. +    memset(new_p16,'\0',16);
  1840. +    E_P16((uchar *)new_passwd,new_p16);
  1841. +
  1842. +    /* Open the smbpaswd file XXXX - we need to parse smb.conf to
  1843. +           get the filename */
  1844. +    if((fp = fopen(pfile, "r+")) == NULL) {
  1845. +        err = errno;
  1846. +        fprintf(stderr, "%s: Failed to open password file %s.\n", 
  1847. +            argv[0], pfile);
  1848. +        errno = err;
  1849. +        perror(argv[0]);
  1850. +        exit(err);
  1851. +    }
  1852. +
  1853. +    /* make sure it is only rw by the owner */
  1854. +    fchmod(fileno(fp),0600);
  1855. +    
  1856. +    /* Lock the smbpasswd file for write. */
  1857. +    if((lockfd=file_lock(pfile,5))<0) {
  1858. +        err = errno;
  1859. +        fprintf(stderr, "%s: Failed to lock password file %s.\n", 
  1860. +            argv[0], pfile);
  1861. +        fclose(fp);
  1862. +        errno = err;
  1863. +        perror(argv[0]);
  1864. +        exit(err);
  1865. +    }
  1866. +
  1867. +    /* Get the smb passwd entry for this user */
  1868. +    smb_pwent = _my_get_smbpwnam( fp, pwd->pw_name, &valid_old_pwd, &seekpos);
  1869. +    if(smb_pwent == NULL) {
  1870. +        fprintf(stderr, "%s: Failed to find entry for user %s in file %s.\n",
  1871. +                argv[0], pwd->pw_name, pfile);
  1872. +        fclose(fp);
  1873. +        file_unlock(lockfd);
  1874. +        exit(1);
  1875. +    }
  1876. +
  1877. +    /* If we are root we don't need to check the old password. */
  1878. +    if( real_uid != 0) {
  1879. +        if( valid_old_pwd == False) {
  1880. +            fprintf(stderr, "%s: User %s is disabled, plase contact your administrator to enable it.\n", argv[0], pwd->pw_name);
  1881. +            fclose(fp);
  1882. +            file_unlock(lockfd);
  1883. +            exit(1);
  1884. +        }
  1885. +        /* Check the old passwd (if there was one). */
  1886. +        if(smb_pwent->smb_passwd != NULL) {
  1887. +            if( memcmp( old_p16, smb_pwent->smb_passwd, 16)) {
  1888. +                fprintf(stderr, "%s: Couldn't change password.\n", argv[0]);
  1889. +                fclose(fp);
  1890. +                file_unlock(lockfd);
  1891. +                exit(1);
  1892. +            }
  1893. +        }
  1894. +    }
  1895. +    /* If we get here either we were root or the old password
  1896. +        checked out ok. */
  1897. +    /* Create the 32 byte representation of the new p16 */
  1898. +    for(i = 0; i < 16; i++) {
  1899. +        sprintf(&ascii_p16[i*2], "%02X", (uchar)new_p16[i]);
  1900. +    }
  1901. +    /* Do an atomic write into the file at the position
  1902. +       defined by seekpos. */
  1903. +    pwfd = fileno(fp);
  1904. +    ret = lseek(pwfd, seekpos - 1, SEEK_SET);
  1905. +    if(ret != seekpos -1) {
  1906. +        err = errno;
  1907. +        fprintf(stderr, "%s: seek fail on file %s.\n", 
  1908. +            argv[0], pfile);
  1909. +        fclose(fp);
  1910. +        errno = err;
  1911. +        perror(argv[0]);
  1912. +        file_unlock(lockfd);
  1913. +        exit(1);
  1914. +    }
  1915. +    /* Sanity check - ensure the character is a ':' */
  1916. +    if(read(pwfd,&c,1) != 1) {
  1917. +        err = errno;
  1918. +        fprintf(stderr, "%s: read fail on file %s.\n", 
  1919. +            argv[0], pfile);
  1920. +        fclose(fp);
  1921. +        errno = err;
  1922. +        perror(argv[0]);
  1923. +        file_unlock(lockfd);
  1924. +        exit(1);
  1925. +    }
  1926. +    if(c != ':') {
  1927. +        fprintf(stderr, "%s: sanity check on passwd file %s failed.\n",
  1928. +            argv[0], pfile);
  1929. +        fclose(fp);
  1930. +        file_unlock(lockfd);
  1931. +        exit(1);
  1932. +    }
  1933. +    if(write(pwfd,ascii_p16,32)!=32) {
  1934. +        err = errno;
  1935. +        fprintf(stderr, "%s: write fail in file %s.\n", 
  1936. +            argv[0], pfile);
  1937. +        fclose(fp);
  1938. +        errno = err;
  1939. +        perror(argv[0]);
  1940. +        file_unlock(lockfd);
  1941. +        exit(err);
  1942. +    }
  1943. +    fclose(fp);
  1944. +    file_unlock(lockfd);
  1945. +    printf("Password changed\n");
  1946. +    return 0;
  1947. +}
  1948. +
  1949. +#else
  1950. +
  1951. +#include "includes.h"
  1952. +
  1953. +int main(int argc, char **argv)
  1954. +{
  1955. +  printf("smb password encryption not selected in Makefile\n");
  1956. +  return 0;
  1957. +}
  1958. +#endif
  1959. diff -u -r --new-file last-version/source/util.c samba-1.9.14alpha10/source/util.c
  1960. --- last-version/source/util.c    Fri Jul  7 15:03:59 1995
  1961. +++ samba-1.9.14alpha10/source/util.c    Tue Jul 11 15:02:59 1995
  1962. @@ -127,6 +127,136 @@
  1963.    return(0);
  1964.  }
  1965.  
  1966. +/****************************************************************************
  1967. +routine to do file locking
  1968. +****************************************************************************/
  1969. +BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type)
  1970. +{
  1971. +#if HAVE_FCNTL_LOCK
  1972. +  struct flock lock;
  1973. +  int ret;
  1974. +
  1975. +#if 1
  1976. +  uint32 mask = 0xC0000000;
  1977. +
  1978. +  /* make sure the count is reasonable, we might kill the lockd otherwise */
  1979. +  count &= ~mask;
  1980. +
  1981. +  /* the offset is often strange - remove 2 of its bits if either of
  1982. +     the top two bits are set. Shift the top ones by two bits. This
  1983. +     still allows OLE2 apps to operate, but should stop lockd from
  1984. +     dieing */
  1985. +  if ((offset & mask) != 0)
  1986. +    offset = (offset & ~mask) | ((offset & mask) >> 2);
  1987. +#else
  1988. +  unsigned long mask = ((unsigned)1<<31);
  1989. +
  1990. +  /* interpret negative counts as large numbers */
  1991. +  if (count < 0)
  1992. +    count &= ~mask;
  1993. +
  1994. +  /* no negative offsets */
  1995. +  offset &= ~mask;
  1996. +
  1997. +  /* count + offset must be in range */
  1998. +  while ((offset < 0 || (offset + count < 0)) && mask)
  1999. +    {
  2000. +      offset &= ~mask;
  2001. +      mask = mask >> 1;
  2002. +    }
  2003. +#endif
  2004. +
  2005. +
  2006. +  DEBUG(5,("fcntl_lock %d %d %d %d %d\n",fd,op,(int)offset,(int)count,type));
  2007. +
  2008. +  lock.l_type = type;
  2009. +  lock.l_whence = SEEK_SET;
  2010. +  lock.l_start = (int)offset;
  2011. +  lock.l_len = (int)count;
  2012. +  lock.l_pid = 0;
  2013. +
  2014. +  errno = 0;
  2015. +
  2016. +  ret = fcntl(fd,op,&lock);
  2017. +
  2018. +  if (errno != 0)
  2019. +    DEBUG(3,("fcntl lock gave errno %d (%s)\n",errno,strerror(errno)));
  2020. +
  2021. +  /* a lock query */
  2022. +  if (op == F_GETLK)
  2023. +    {
  2024. +      if ((ret != -1) &&
  2025. +      (lock.l_type != F_UNLCK) && 
  2026. +      (lock.l_pid != 0) && 
  2027. +      (lock.l_pid != getpid()))
  2028. +    {
  2029. +      DEBUG(3,("fd %d is locked by pid %d\n",fd,lock.l_pid));
  2030. +      return(True);
  2031. +    }
  2032. +
  2033. +      /* it must be not locked or locked by me */
  2034. +      return(False);
  2035. +    }
  2036. +
  2037. +  /* a lock set or unset */
  2038. +  if (ret == -1)
  2039. +    {
  2040. +      DEBUG(3,("lock failed at offset %d count %d op %d type %d (%s)\n",
  2041. +           offset,count,op,type,strerror(errno)));
  2042. +
  2043. +      /* perhaps it doesn't support this sort of locking?? */
  2044. +      if (errno == EINVAL)
  2045. +    {
  2046. +      DEBUG(3,("locking not supported? returning True\n"));
  2047. +      return(True);
  2048. +    }
  2049. +
  2050. +      return(False);
  2051. +    }
  2052. +
  2053. +  /* everything went OK */
  2054. +  DEBUG(5,("Lock call successful\n"));
  2055. +
  2056. +  return(True);
  2057. +#else
  2058. +  return(False);
  2059. +#endif
  2060. +}
  2061. +
  2062. +/*******************************************************************
  2063. +lock a file - returning a open file descriptor or -1 on failure
  2064. +The timeout is in seconds. 0 means no timeout
  2065. +********************************************************************/
  2066. +int file_lock(char *name,int timeout)
  2067. +{  
  2068. +  int fd = open(name,O_RDWR|O_CREAT,0666);
  2069. +  time_t t=0;
  2070. +  if (fd < 0) return(-1);
  2071. +
  2072. +#if HAVE_FCNTL_LOCK
  2073. +  if (timeout) t = time(NULL);
  2074. +  while (!timeout || (time(NULL)-t < timeout)) {
  2075. +    if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)) return(fd);    
  2076. +    msleep(LOCK_RETRY_TIMEOUT);
  2077. +  }
  2078. +  return(-1);
  2079. +#else
  2080. +  return(fd);
  2081. +#endif
  2082. +}
  2083. +
  2084. +/*******************************************************************
  2085. +unlock a file locked by file_lock
  2086. +********************************************************************/
  2087. +void file_unlock(int fd)
  2088. +{
  2089. +  if (fd<0) return;
  2090. +#if HAVE_FCNTL_LOCK
  2091. +  fcntl_lock(fd,F_SETLK,0,1,F_UNLCK);
  2092. +#endif
  2093. +  close(fd);
  2094. +}
  2095. +
  2096.  /*******************************************************************
  2097.  a gettimeofday wrapper
  2098.  ********************************************************************/
  2099. diff -u -r --new-file last-version/source/version.h samba-1.9.14alpha10/source/version.h
  2100. --- last-version/source/version.h    Sun Jul  9 16:54:33 1995
  2101. +++ samba-1.9.14alpha10/source/version.h    Tue Jul 11 16:47:52 1995
  2102. @@ -1 +1 @@
  2103. -#define VERSION "1.9.14alpha9"
  2104. +#define VERSION "1.9.14alpha10"
  2105.